#include <iostream>
#include <memory>

// Q1: Can enable_shared_from_this inherit?
class Base : public std::enable_shared_from_this<Base> {
public:
    virtual ~Base() = default;

    std::shared_ptr<Base> GetSelf()
    {
        return shared_from_this();
    }

    virtual void Func()
    {
        std::cout << "Base Func" << std::endl;
    }
};

class Derived1 : public Base {
public:
    void Func() override
    {
        std::cout << "Derived1 Func" << std::endl;
    }
};

class Derived2 : public Base {
public:
    void Func() override
    {
        std::cout << "Derived2 Func" << std::endl;
    }
};

void __attribute__((constructor)) test()
{
}

int main()
{
    auto base = std::make_shared<Derived1>();
    base->GetSelf()->Func(); // "Derived1 Func"
    // A1: enable_shared_from_this can inherit.
    return 0;
}
